function random(min,max){//随机数
return Math.floor(Math.random()*(max-min+1)+min);}

function checkARC(arc1, arc2) { //检测圆形碰撞
	var disR = arc1.r + arc2.r;
	var chax = Math.abs(arc1.x - arc2.x);
	var chay = Math.abs(arc1.y - arc2.y);
	if(chax < disR && chay < disR && Math.sqrt(chax * chax + chay * chay) < disR) {
		alert(1);
	}
}

function checkPeng(obj1, obj2) { //检测矩形碰撞
	var disX = (obj1.w + obj2.w) / 2;
	var disY = (obj1.h + obj2.h) / 2;
	var centerX = Math.abs(obj1.x + (obj1.w / 2) - (obj2.x + (obj2.w / 2)));
	var centerY = Math.abs(obj1.y + (obj1.h / 2) - (obj2.y + (obj2.h / 2)));
	if(centerX < disX && centerY < disY) {
		return true;
	} else {
		return false;
	}
}

function addPath(type, url, par) { //ajax原生方法
	var str = "";
	var arr = [];
	for(var prop in par) {
		arr.push(prop + "=" + par[prop]);
	}
	str = arr.join("&");
	if(type.toLowerCase() == "get") {
		return url + "?" + str;
	} else if(type.toLowerCase() == "post") {
		return str;
	}
}

function ajaxNetWork(type, url, par, fn) { //ajax原生 跨域
	var ajaxObj;
	if(window.XMLHttpRequest) {
		ajaxObj = new XMLHttpRequest();
	} else {
		ajaxObj = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(type.toLowerCase() == "get") {
		var allURL = addPath(type, url, par);
		ajaxObj.open(type, allURL, true);
		ajaxObj.send();
	} else if(type.toLowerCase() == "post") {
		ajaxObj.open(type, url, true);
		ajaxObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		// send() 后面填写的是发送的xx=xx&xx=xx的body体
		// 不要拼接在网址?后面, 则是单独在send里发送
		ajaxObj.send(addPath(type, url, par));
	}
	ajaxObj.onreadystatechange = function() {
		if(ajaxObj.readyState == 4) {
			if(ajaxObj.status == 200) {
				fn(ajaxObj.responseText);
			}
		}
	}
}

//封装的滚轮事件
mouseWheel(div, function(down, evObj) { //回调函数；
	if(down) {
		div.style.width = div.offsetWidth + 10 + "px";
		div.style.height = div.offsetHeight + 10 + "px";
	} else {
		div.style.width = div.offsetWidth - 10 + "px";
		div.style.height = div.offsetHeight - 10 + "px";
	}
});
//arguments 本身是数组 用来接收函数中未定义的参数

function mouseWheel(obj, fn) {
	var ff = window.navigator.userAgent.indexOf("Firefox");
	if(ff != -1) {
		obj.addEventListener("DOMMouseScroll", wheel, false);
	} else {
		obj.onmousewheel = wheel;
	}
	function wheel(ev) {
		var evObj = ev || window.event;
		var down = true;
		if(evObj.detail) {
			down = evObj.detail < 0;
		} else {
			down = evObj.wheelDelta > 0;
		}
		//回调函数  ，把值回传给调用处；
		fn(down, evObj);
		//取消默认事件
		if(ev.preventDefault) {
			ev.preventDefault();
		}
		return false;
	}
}



//cookie 使用方法封装;
    function setCookie(name, value, expires){
        var date = new Date();
        date.setTime(date.getTime() + expires * 24 * 3600 * 1000);
        document.cookie = name + "=" + value + ";expires=" + date.toUTCString();
    }
    function getCookie(name){
        var cookie = document.cookie;
        var cookieArr = cookie.split(";");
        for (var i = 0; i < cookieArr.length; i++){
            var cookies = cookieArr[i].split("=");
        }
//        trim() 防止2边有空格
        if (cookies[0].trim() == name){
            return cookies[1].trim();
        }
    }


//使用样例:
// 过期时间不要设置0, 位数为天
//  setCookie("shabi", "caonima", 1);
//  console.log(getCookie("shabi"));

//封装的清除定时器的函数

function clearTimer(){
var timer=setTimeout(function(){},1);
for(var i=1;i<timer;i++){
clearInterval(i);
}
}

//封装的大图滚动(局限性比较大 写手机端的时候封装的)
//引用第一个swiper 方法; 样式自己写 position 定位在一排就可以
function datugundong(obj_min_wrap, obj_nav_dian_arr, div_page_wrap) {
	var thenX = 0; //开始点击的X坐标
	var index = 0; //记录当前显示出来的页面;
	obj_min_wrap.style.height = screenHeight * 0.2854076 + "px";
	obj_min_wrap.addEventListener("touchstart", start, false);
	obj_min_wrap.addEventListener("touchend", end, false);
	obj_nav_dian_arr[index].style.backgroundColor = "rgb(169,169,169)";
}

function start(ev) {
	var event = ev || window.event;
	thenX = event.changedTouches[0].pageX;
}

function end(ev) {
	var event = ev || window.event;
	event.preventDefault()
	var nowX = event.changedTouches[0].pageX;
	if(nowX > thenX) {
		if(div_page_wrap[0].offsetLeft >= 0) {
			console.log("到头了");
		} else {
			for(var i = 0; i < div_page_wrap.length; i++) {
				Scroll(div_page_wrap[i], false);
			}
			index--;
			for(var i = 0; i < obj_nav_dian_arr.length; i++) {
				obj_nav_dian_arr[i].style.backgroundColor = "";
			}
			obj_nav_dian_arr[index].style.backgroundColor = "rgb(169,169,169)";
		}
	} else if(nowX < thenX) {
		if(div_page_wrap[obj_nav_dian_arr.length-1].offsetLeft > 0) {
			for(var i = 0; i < div_page_wrap.length; i++) {
				Scroll(div_page_wrap[i], true);
			}
			index++;
			for(var i = 0; i < obj_nav_dian_arr.length; i++) {
				obj_nav_dian_arr[i].style.backgroundColor = "";
			}
			obj_nav_dian_arr[index].style.backgroundColor = "rgb(169,169,169)";
		} else {
			console.log("到头了");
		}
	}
	obj_min_wrap.removeEventListener("touchstart", start, false);
	obj_min_wrap.removeEventListener("touchend", end, false);
	setTimeout(function() {
		obj_min_wrap.addEventListener("touchstart", start, false);
		obj_min_wrap.addEventListener("touchend", end, false);
	}, 1000);
}

function Scroll(obj, bol) {
	if(bol) {
		//					//左滑
		obj.style.left = obj.offsetLeft - screenWidth + "px";
	} else {
		//					//右滑
		obj.style.left = obj.offsetLeft + screenWidth + "px";
	}
}
